package com.bistu.xiong.tulingrobotchat.frags.account;

import android.content.Context;
import android.widget.EditText;

import com.bistu.xiong.common.app.PresenterFragment;
import com.bistu.xiong.factory.presenter.accout.RegisterContract;
import com.bistu.xiong.factory.presenter.accout.RegisterPresenter;
import com.bistu.xiong.tulingrobotchat.R;
import com.bistu.xiong.tulingrobotchat.activities.MainActivity;
import com.bistu.xiong.tulingrobotchat.activities.UpdateUserActivity;

import net.qiujuer.genius.ui.widget.Loading;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by XiongXiaoJun on 2017/12/04.
 */

public class RegisterFragment extends PresenterFragment<RegisterContract.Presenter> implements RegisterContract.View{
    @BindView(R.id.edit_phone)
    EditText mPhone;
    @BindView(R.id.edit_password)
    EditText mPassword;
    @BindView(R.id.edit_name)
    EditText mName;

    @BindView(R.id.loading)
    Loading mLoading;

    private AccountTrigger mAccountTrigger;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //拿到我们的Activity的引用，因为AccountTrigger接口的实现在Activity中
        mAccountTrigger = (AccountTrigger) context;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_register;
    }

    @Override
    public void showLoading() {
        super.showLoading();

    }

    @Override
    protected RegisterPresenter initPresenter() {
        return new RegisterPresenter(this);
    }

    /**
     * 切换当前页面为登录页面
     */
    @OnClick(R.id.txt_go_login)
    void onShowLoginClick(){
        //让AccountActivity进行界面切换
        mAccountTrigger.triggerView();
    }

    /**
     * 提交用户信息 进行注册操作
     */
    @OnClick(R.id.btn_submit)
    void onSubmitClick(){
        String phone = mPhone.getText().toString();
        String password = mPassword.getText().toString();
        String name = mName.getText().toString();
        mPresenter.register(name,password,phone);
    }

    @Override
    public void registerSuccess() {
        MainActivity.show(getContext());
        getActivity().finish();
    }
}
